#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

ll read() {
    ll x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e6 + 10;
const ll inf = 1e18;
const db pw = 3. / 2;

ll dis[N], pot[N];
int cnt, t[N];

void init() {
	unordered_map < ll, bool > vis;
	unordered_map < ll, int > id;
	vis[1] = true; queue < ll > q; q.push(1);
	rep(i, 1, 22) t[i] = pow(i, pw);
	while(q.size()) {
		ll x = q.front(); q.pop(); pot[++cnt] = x;
		rep(i, 2, 22) {
			if(i * i * x > inf) break;
			if(!vis[i * i * x]) vis[i * i * x] = true, q.push(i * i * x);
		}
	}
	sort(pot + 1, pot + cnt + 1);
	rep(i, 1, cnt) id[pot[i]] = i;
	dis[1] = 1;
	rep(i, 1, cnt) {
		ll x = pot[i];
		rep(j, 2, 22) {
			if(j * j * x > inf) break;
			dis[id[j * j * x]] = max(dis[id[j * j * x]], dis[i] * t[j]); 
		}
	}
	rep(i, 1, cnt) dis[i] = max(dis[i], dis[i - 1]);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	init(); int T = in;
	while(T--) {
		ll x = in, y = in; y /= x;
		int pos = upper_bound(pot + 1, pot + cnt + 1, y) - pot - 1;
		printf("%lld\n", dis[pos]);
	} return 0;
}
